;

#pragma once

#include "type.h"

#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

class FrameAnimation;

#define RM                      ResourceManager::getInstance()
#define MAKE_SPRITE(s)          RM->makeSprite(s)
#define MAKE_SPRITEFRAME(s)     RM->makeSpriteFrame(s)
#define T(s)                    RM->getString(s)

/*
    handle loading strings, game data
 */
class ResourceManager {
public:
    static ResourceManager* getInstance();
	virtual ~ResourceManager();

	void init();

	void loadAnimationData();

	bool hasAnimationInfo(const string& key);
	AnimationInfo getAnimationInfo(const string& key);

    void loadStrings();
    static string loadTextFile(const string& fileName, bool absolute=false);

    // load the locale file, string.xml
    void loadLocaleString(const char* rootPath, const char* filename, const char* locale, bool absolutePath);

    // get a value from string.xml
    const char* getValue(const char* key);

    CCSprite* makeSprite(const string& name);
    CCSpriteFrame* makeSpriteFrame(const string& key);
    CCSprite* makeSpriteFromResource(const string& name);
    FrameAnimation * createAnimation(const string& animKey, const CCPoint& location);
    CCMenuItemSprite *makeButton(const char *nameNormal, const char *nameSelected, const char *nameDisabled, CCNode *target, SEL_MenuHandler selector, CCNode *parent);
    CCMenuItemSprite *makeBackButton(CCNode *target, SEL_MenuHandler selector, CCNode *parent, bool isRoundButton = false);
	CCLabelTTF *makeButtonLabel(const char *text, int fontSize, CCNode *parent);

    void removeTextureForKey(const string& file);
    void removeSpriteFramesFromFile(const string& file);

    void loadTexturesFromPList(const string& fn, bool absolutePath = false);

private:
    static ResourceManager* _instance;
    ResourceManager();

	static string decodeBuffer(const char* str, int length);

private:
	map<string, string> _mapResource;
	map<string, AnimationInfo> _mapAnimationInfo;
};
